package com.hp.demo.vteam.action;

import java.util.Date;
import javax.jdo.Query;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.google.appengine.api.datastore.KeyFactory;
import com.hp.demo.vteam.bean.InforKind;
import com.hp.demo.vteam.bean.Information;

public class InforKindServlet extends BaseServlet {
	private static final long serialVersionUID = 488512511249820513L;

	@Override
	public void edit (HttpServletRequest request, HttpServletResponse response)
    throws Exception {

        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String desc = request.getParameter("desc");
        Date date = new Date();
        InforKind inforKind = null;
        if(id!=null && !id.isEmpty()){
        	inforKind = pm.getObjectById(InforKind.class, Long.parseLong(id));
            inforKind.setName(name);
            inforKind.setDesc(desc);
            inforKind.setAddedTime(date);
            inforKind.setAddedBy(user);
        }
       	if(inforKind == null){
        	inforKind = new InforKind(name,desc, user, date);    
        }
        super.baseEdit(request, response, inforKind);
		response.getWriter().print(String.format(SUCCESS_MSG, "true","操作成功" ));
	}
	
	@Override
	public void del (HttpServletRequest request, HttpServletResponse response)
    throws Exception {

        String id = request.getParameter("id");
        InforKind inforKind = null;

        if(id!=null && !id.isEmpty()){
        	inforKind = pm.getObjectById(InforKind.class, Long.parseLong(id));
        	 super.baseDel(request, response, inforKind);
        }
		response.getWriter().print(String.format(SUCCESS_MSG, "true","操作成功" ));
	}

	@Override
	public void search (HttpServletRequest request, HttpServletResponse response)
    throws Exception {
		super.baseSearch(request, response, InforKind.class);
	}
}

